package com.wm.wmim.server.service.impl;

import com.wm.wmim.server.dao.ChatListDao;
import com.wm.wmim.server.dbservice.UserInfoDbService;
import com.wm.wmim.server.dbservice.impl.UserInfoDbServiceImpl;
import com.wm.wmim.server.dto.bo.resp.ChatListRespBO;
import com.wm.wmim.server.entity.ChatListDO;
import com.wm.wmim.server.entity.UserInfoDO;
import com.wm.wmim.server.mapstruct.ChatListMapStruct;
import com.wm.wmim.server.service.ChatListService;
import com.wm.wmim.server.dbservice.ChatListDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 聊天列表表(ChatList)表服务实现类
 *
 * @author weiming
 * @since 2025-02-20 23:16:30
 */
@Service
public class ChatListServiceImpl implements ChatListService {


    @Resource
    private ChatListDbService chatListDbService;
    @Resource
    private ChatListMapStruct chatListMapStruct;
    @Resource
    private UserInfoDbService userInfoDbService;


    @Override
    public List<ChatListRespBO> listChat(Long userId) {
        List<ChatListDO> chatListDOList = chatListDbService.listByUserId(userId);
        List<Long> friendIdList = chatListDOList.stream().map(ChatListDO::getFriendId).collect(Collectors.toList());
        List<UserInfoDO> userInfoDOS = userInfoDbService.listByIds(friendIdList);

        List<ChatListRespBO> respBOS= chatListMapStruct.fromDOToBO(chatListDOList, userInfoDOS);
        return respBOS;
    }
}

